package com.example.brain2;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class ChooseThemeActivity extends Activity {

	protected static final String TAG = "ChooseThemeActivity";
	private int counterUserClicksDifficulty = 0;
	private int counterUserClicksTheme = 0;
	private static final int NUMBER_USER_CHOICES = 2;
	private int[] checkUserChoice = new int[NUMBER_USER_CHOICES];

	RadioGroup userChoiceThemeRadioGroup;
	RadioGroup userChoiceDifficultyRadioGroup;

	RadioButton animalsRadioButton;
	RadioButton weaponsRadioButton;
	RadioButton objectsRadioButton;
	RadioButton easyRadioButton;
	RadioButton mediumRadioButton;
	RadioButton hardRadioButton;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_choose_game);
		Effects.getInstance().init(this);
		userChoiceThemeRadioGroup = (RadioGroup) findViewById(R.id.radiogroup_theme);
		animalsRadioButton = (RadioButton) findViewById(R.id.radiobutton_animals);
		weaponsRadioButton = (RadioButton) findViewById(R.id.radiobutton_weapons);
		objectsRadioButton = (RadioButton) findViewById(R.id.radiobutton_objects);

		userChoiceDifficultyRadioGroup = (RadioGroup) findViewById(R.id.radiogroup_difficulty);
		easyRadioButton = (RadioButton) findViewById(R.id.radiobutton_easy);
		mediumRadioButton = (RadioButton) findViewById(R.id.radiobutton_medium);
		hardRadioButton = (RadioButton) findViewById(R.id.radiobutton_hard);

		// create a listener for all the buttons
		OnClickListener listener = new OnClickListener() {
			@Override
			public void onClick(View view) {
				Effects.getInstance().playSound(Effects.SOUND_1);
				boolean isChecked = ((RadioButton) view).isChecked();
				switch (view.getId()) {
				case R.id.radiobutton_animals:
					if (isChecked
							&& counterUserClicksTheme <= NUMBER_USER_CHOICES / 2) {
						checkUserChoice[0] = 1;
						counterUserClicksTheme++;
					}
					break;
				case R.id.radiobutton_weapons:
					if (isChecked
							&& counterUserClicksTheme <= NUMBER_USER_CHOICES / 2) {
						checkUserChoice[0] = 2;
						counterUserClicksTheme++;
					}
					break;
				case R.id.radiobutton_objects:
					if (isChecked
							&& counterUserClicksTheme <= NUMBER_USER_CHOICES / 2) {
						checkUserChoice[0] = 3;
						counterUserClicksTheme++;
					}
					break;
				case R.id.radiobutton_easy:
					if (isChecked
							&& counterUserClicksDifficulty <= NUMBER_USER_CHOICES / 2) {
						checkUserChoice[1] = 1;
						counterUserClicksDifficulty++;
					}
					break;
				case R.id.radiobutton_medium:
					if (isChecked
							&& counterUserClicksDifficulty <= NUMBER_USER_CHOICES / 2) {
						checkUserChoice[1] = 2;
						counterUserClicksDifficulty++;
					}
					break;
				case R.id.radiobutton_hard:
					if (isChecked
							&& counterUserClicksDifficulty <= NUMBER_USER_CHOICES / 2) {
						checkUserChoice[1] = 3;
						counterUserClicksDifficulty++;
					}
					break;
				}
				if (counterUserClicksTheme > 1) {
					counterUserClicksTheme--;
				}
				if (counterUserClicksDifficulty > 1) {
					counterUserClicksDifficulty--;
				}
				if (counterUserClicksDifficulty == 1
						&& counterUserClicksTheme == 1) {
					Intent i = new Intent(ChooseThemeActivity.this,
							ActualGameActivity.class);
					Bundle kofa = new Bundle();
					kofa.putIntArray("ImageTypes", checkUserChoice);
					i.putExtras(kofa);
					startActivity(i);
				}
			}
		};
		animalsRadioButton.setOnClickListener(listener);
		weaponsRadioButton.setOnClickListener(listener);
		objectsRadioButton.setOnClickListener(listener);
		easyRadioButton.setOnClickListener(listener);
		mediumRadioButton.setOnClickListener(listener);
		hardRadioButton.setOnClickListener(listener);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.new_game, menu);
		return true;
	}

	// choose theme and add 1st value ot int[] array
	// private void userChoiceThemeListener() {
	//
	// userChoiceThemeRadioGroup
	// .setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
	//
	// @Override
	// public void onCheckedChanged(RadioGroup group, int checkedId) {
	// checkUserChoice[0] = (animalsRadioButton.isChecked()) ? 1 : 0;
	// checkUserChoice[0] = (weaponsRadioButton.isChecked()) ? 2 : 0;
	// checkUserChoice[0] = (objectsRadioButton.isChecked()) ? 3 : 0;
	// }
	// });
	// }

}
